#include <bits/stdc++.h>

using namespace std;
struct safetyIndex
{
    int y,ones_result,zeros_result,zeros_left,ones_right;
    safetyIndex()
    {
        zeros_result=0;
        ones_result=0;
    }
    bool operator<(const safetyIndex& si)
    {
        return this->y<si.y;
    }
};
int main_67()
{
    int m,yi,result_i,zeros=0,ones=0,pred_true=-1,ans,theta;
    scanf("%d",&m);
    unordered_map<int,safetyIndex> y2result;
    for (int i=0;i<m ;++i )
    {
        scanf("%d%d",&yi,&result_i);
        y2result[yi].y=yi;
        if (result_i==0)
        {
            ++y2result[yi].zeros_result;
        }
        else
        {
            ++y2result[yi].ones_result;
        }
    }
    vector<safetyIndex> si;
    for (auto ele:y2result)
    {
        si.push_back(ele.second);
    }
    sort(si.begin(),si.end());
    si[0].zeros_left=0;
    for (int i=1;i<si.size();++i )
    {
        zeros+=si[i-1].zeros_result;
        si[i].zeros_left=zeros;
    }
    for (int i=si.size()-1; i>=0;--i )
    {
        ones+=si[i].ones_result;
        ans=si[i].zeros_left+ones;
        if (ans>pred_true)
        {
            pred_true=ans;
            theta=si[i].y;
        }
    }
    printf("%d",theta);
    return 0;
}
